package morningcat.study.spring.beanFactory;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.StaticListableBeanFactory;

/**
 * @describe: 类描述信息
 * @author: morningcat.zhang
 * @date: 2019/3/4 9:38 AM
 */
public class BeanFactoryTest {

    @Test
    public void test1() {

        StaticListableBeanFactory beanFactory = new StaticListableBeanFactory();
        beanFactory.addBean("helloService", new HelloServiceImplOne());

        HelloService service = beanFactory.getBean("helloService", HelloService.class);
        HelloService service2 = (HelloService) beanFactory.getBean("helloService");
        service.hello();
        service2.hello();
        System.out.println(service == service2);
    }

    @Test
    public void test2() {

        StaticListableBeanFactory beanFactory = new StaticListableBeanFactory();
        beanFactory.addBean("helloService", new HelloServiceImplOne());
        //beanFactory.addBean("helloService2", new HelloServiceImplTwo());

        HelloService service = beanFactory.getBean(HelloService.class);
        service.hello();
    }
}
